import Vue from 'vue'
import Vuex from 'vuex'
import home from './home'
import search from './search'

Vue.use(Vuex)

import { getNewAndHotGoodsInfo } from "@/api/pages/new-hot-goods";
export default new Vuex.Store({
  state: {
    addressId: '',
    cartCount: 0,
  },
  mutations: {
    setAddressId(state, id) {
      state.addressId = id;
      console.log(state.addressId);
    },

    getCartCount(state,res){
      state.cartCount = res.data.length;
      console.log(state.cartCount);
    }
  },
  actions: {
    asyncGetCartCount({state,commit}){
      getNewAndHotGoodsInfo({ order: 'desc', isNew:0, isHot:0 }).then(res=>{
        commit('getCartCount',res)
      })
    }
  },
  modules: {
    home: home,
    search: search,
  }
})